﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Ewts.Storage
{
    public partial class InstorageSelect : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                dataBind();
            }
        }
        protected void dataBind()
        {
            List<DataLib.Model.InStorage> instorageList = new DataLib.BLL.InStorage().GetModelList("1=1");

            if (instorageList.Count == 0 || instorageList == null) return;
            DataTable table = new DataTable();
            #region 添加列
            table.Columns.AddRange(new DataColumn[] { 
                new DataColumn("loadnumno"),
                new DataColumn("cumName"),
                new DataColumn("instorageno"),
                new DataColumn("instoragedate"),
                new DataColumn("agoGoodsID"),
                new DataColumn("agoGoodsCode"),
                new DataColumn("agoName"),
                new DataColumn("agoGwt"),
                new DataColumn("agoNwt"),
                new DataColumn("agoCount"),
                new DataColumn("agoLdh"),
                new DataColumn("afterGoodscode"),
                new DataColumn("afterDescriber"),
                new DataColumn("afterGwt"),
                new DataColumn("afterTare1"),
                new DataColumn("afterTare2"),
                new DataColumn("afterNwt"),
                new DataColumn("afterCount"),
                new DataColumn("afterClassify"),
                new DataColumn("afterPosition"),
                new DataColumn("afterBarcode"),
                new DataColumn("afterBoxid"),
            }); 
            #endregion

            #region 绑定行数据
            for (int i = 0; i < instorageList.Count; i++)
            {
                DataLib.Model.InStorage instorageModel = instorageList[i];

                DataRow row = table.NewRow();
                row["instorageno"] = instorageModel.wrlno;
                row["instoragedate"] = instorageModel.instoragetime;
                DataTable unpross = new DataLib.BLL.unProcessed().GetList(" inSid=" + instorageModel.id).Tables[0];
                if (unpross.Rows.Count > 0 && unpross != null)
                {
                    row["agoGoodsCode"] = unpross.Rows[0]["GoodsCode"];
                    row["agoName"] = unpross.Rows[0]["GoodsName"];
                    row["agoGwt"] = unpross.Rows[0]["gwt"];
                    row["agoNwt"] = unpross.Rows[0]["nwt"];
                    row["agoCount"] = unpross.Rows[0]["qty"];
                    row["agoLdh"] = unpross.Rows[0]["continNo"];
                }

                DataTable barcode = new DataLib.BLL.BarCode().GetList("InStrorageID=" + instorageModel.id).Tables[0];
                if (barcode.Rows.Count > 0 && barcode != null)
                {
                    row["agoGoodsID"] = barcode.Rows[0]["packageno"];
                    row["loadnumno"] = barcode.Rows[0]["loadnumv"];
                    row["afterGoodscode"] = barcode.Rows[0]["goodscode"];
                    row["afterDescriber"] = "无";
                    row["afterGwt"] = barcode.Rows[0]["gwt"];
                    row["afterTare1"] = barcode.Rows[0]["tare1"];
                    row["afterTare2"] = barcode.Rows[0]["tare2"];
                    row["afterNwt"] = barcode.Rows[0]["nwt"];
                    row["afterCount"] = barcode.Rows[0]["boxcount"];
                    row["afterClassify"] = barcode.Rows[0]["comeunder"];
                    row["afterPosition"] = barcode.Rows[0]["stroageNo"];
                    row["afterBarcode"] = barcode.Rows[0]["barcodevalue"];
                    row["afterBoxid"] = barcode.Rows[0]["packageno"];
                    DataTable loadnum = new DataLib.BLL.LoadNum().GetList(" loadnum =" + barcode.Rows[0]["loadnumv"]).Tables[0];

                    if (loadnum.Rows.Count > 0 && loadnum != null)
                    {
                        int id = Convert.ToInt32(loadnum.Rows[0]["customerid"]);
                        DataTable custormer = new DataLib.BLL.Cumtomer().GetList(" id=" + id).Tables[0];
                        if (custormer.Rows.Count > 0 && custormer != null)
                        {
                            row["cumName"] = custormer.Rows[0]["companyname"];
                        }
                    }
                }
                table.Rows.Add(row);
            } 
            #endregion

            rept.DataSource = table;
            rept.DataBind();

        }
    }
}